package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/4/3 21:37
 */
public class J11 {

    /** https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/ */
    public static int minArray(int[] numbers) {
        int l = 0, r = numbers.length-1;
        int m = -1;
        while (l < r) {
            m = l + ( (r-l) >> 1);
            if(numbers[m] < numbers[r]) {
                r = m;
            }else if(numbers[m] > numbers[r]) {
                l = m+1;
            }else {
                r--;
            }
        }
        return numbers[l];
    }

    // for test
    public static void main(String[] args) {
        int[] numbers = {2,2,2,0,1};
        System.out.println(minArray(numbers));
    }

}
